﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.IO;
using Baimasoft.FrameWork.Base;
using Baimasoft.Manage.SqlServerDAL;

public partial class DocumentManage_Document_Left : System.Web.UI.Page
{
    BaiMaSoft.Conn.DataConn MyDataConn = new BaiMaSoft.Conn.DataConn();
    public SqlDataAdapter myadapter;
    public DataSet myds;
    public DataTable mytb;
    public DataColumn mycolumn;
    public string filedtotal = "";
    public string sDeptHtml = "",sProjectHtml="";

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            string sChoiceFolderCol = "0";
            if ((string)Session["Baimasoft_User_LogonID"] != "admin")
            {
                sChoiceFolderCol =AspNetHelper.GetRightFolderIDCol();
            }

            string sID = "0";
            IniDocInfo(sID, sChoiceFolderCol);
            IniProjectInfo(sID);
        }
    }

    #region 文档树
    public void IniDocInfo(string HID,string sPageIDCol)
    {
        MyDataConn.Connection.Open();
        string sSql = @"  SELECT ID, PaterID as ParentID,ChildNumber, Name,replace(Path,'\','\\\\') as Path, PaterPath FROM DataFolder order by DOrder ";

        myadapter = new SqlDataAdapter(sSql, MyDataConn.Connection);
        myds = new DataSet();
        myadapter.Fill(myds, "T_DocumentManage");
        mytb = myds.Tables["T_DocumentManage"];

        foreach (DataColumn mycolumn in mytb.Columns)
        {
            filedtotal = filedtotal + mycolumn.ColumnName + ",";
        }

        sDeptHtml = sDeptHtml + "<script language=\"javascript\" type=\"text/javascript\">";
        filedtotal = filedtotal.Substring(0, filedtotal.Length - 1);
        sDeptHtml = sDeptHtml + " function tree(" + filedtotal + "){";
        string[] sfiledtotal = filedtotal.Split(',');
        int nfiledtotal = sfiledtotal.Length;
        for (int i = 0; i < nfiledtotal; i++)
        {
            sDeptHtml = sDeptHtml + "this." + sfiledtotal[i] + "=" + sfiledtotal[i] + ";";
        }

        if (mytb.Rows.Count > 0)
        {
            int iRowCount = mytb.Rows.Count - 1;
            sDeptHtml = sDeptHtml + "}var trees =new Array(" + iRowCount + ");";
        }
        else
        {
            sDeptHtml = sDeptHtml + "}var trees =new Array(0);";
        }

        for (int j = 0; j < mytb.Rows.Count; j++)
        {
            sDeptHtml = sDeptHtml + "trees[" + j + "] = new tree(";
            string temp = "";
            for (int k = 0; k < mytb.Columns.Count; k++)
            {
                temp = temp + "'" + mytb.Rows[j][k] + "'";
                if (k != mytb.Columns.Count - 1)
                {
                    temp = temp + ",";
                }
            }
            sDeptHtml = sDeptHtml + temp + ");";
        }
        sDeptHtml = sDeptHtml + "GetSuperOrgID('" + HID + "');showtree(0,'" + sPageIDCol + "');SpreadNewOrgTree();";
        sDeptHtml = sDeptHtml + "</script>";
        sDeptHtml = sDeptHtml + "";
        MyDataConn.Connection.Close();
    }
    #endregion

    #region 项目树
    public void IniProjectInfo(string HID)
    {
        filedtotal = "";
        MyDataConn.Connection.Open();
        string sSql = @" SELECT project_id AS ID, project_pid AS ParentID, ChildNumber, project_name as Name, '11' AS Path, 
                                  '22' AS PaterPath
                            FROM Bas_project ";

        myadapter = new SqlDataAdapter(sSql, MyDataConn.Connection);
        myds = new DataSet();
        myadapter.Fill(myds, "Bas_project");
        mytb = myds.Tables["Bas_project"];

        foreach (DataColumn mycolumn in mytb.Columns)
        {
            filedtotal = filedtotal + mycolumn.ColumnName + ",";
        }

        sProjectHtml = sProjectHtml + "<script language=\"javascript\" type=\"text/javascript\">";
        filedtotal = filedtotal.Substring(0, filedtotal.Length - 1);
        sProjectHtml = sProjectHtml + " function Projecttree(" + filedtotal + "){";
        string[] sfiledtotal = filedtotal.Split(',');
        int nfiledtotal = sfiledtotal.Length;
        for (int i = 0; i < nfiledtotal; i++)
        {
            sProjectHtml = sProjectHtml + "this." + sfiledtotal[i] + "=" + sfiledtotal[i] + ";";
        }

        if (mytb.Rows.Count > 0)
        {
            int iRowCount = mytb.Rows.Count - 1;
            sProjectHtml = sProjectHtml + "}var Projecttrees =new Array(" + iRowCount + ");";
        }
        else
        {
            sProjectHtml = sProjectHtml + "}var Projecttrees =new Array(0);";
        }

        for (int j = 0; j < mytb.Rows.Count; j++)
        {
            sProjectHtml = sProjectHtml + "Projecttrees[" + j + "] = new Projecttree(";
            string temp = "";
            for (int k = 0; k < mytb.Columns.Count; k++)
            {
                temp = temp + "'" + mytb.Rows[j][k] + "'";
                if (k != mytb.Columns.Count - 1)
                {
                    temp = temp + ",";
                }
            }
            sProjectHtml = sProjectHtml + temp + ");";
        }
        sProjectHtml = sProjectHtml + "GetSuperProjectID('" + HID + "');show_Projecttree(0,0);SpreadNewProjectTree();";
        sProjectHtml = sProjectHtml + "</script>";
        sProjectHtml = sProjectHtml + "";
        MyDataConn.Connection.Close();
    }

    #endregion
}
